package com.hmy.contract.client;

import com.hmy.ccp.common.result.FeignResult;
import com.hmy.ccp.common.result.Results;
import com.hmy.ccp.error.annotations.HmyFeignController;
import com.hmy.contract.bo.request.contract.*;
import com.hmy.contract.bo.response.contract.ContractInfoListResponse;
import com.hmy.contract.bo.response.contract.ContractInfoResponse;
import com.hmy.contract.bo.response.contract.ContractSignTaskCancelResponse;
import com.hmy.contract.bo.response.contract.CreateContractResponse;
import com.hmy.contract.service.contract.IContractFeignService;
import com.hmy.contract.service.contract.IContractService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @Description 合同管理feign客户端
 * @Author seven.qi
 * @Date 2023/12/19 19:32
 * @Version 1.0
 */

@Slf4j
@Api(tags = "合同管理feign客户端")
@RestController("feignContractClientController")
@Validated
@HmyFeignController
public class ContractClientController {

    @Resource
    private IContractService contractService;

    @Resource
    private IContractFeignService contractFeignService;

    @PostMapping("/feign/contract/contractInfo")
    @ApiOperation("根据合同id查询合同详情")
    public FeignResult<ContractInfoResponse> contractInfo(@RequestBody ContractInfoRequest contractInfoRequest) {
        ContractInfoResponse contractInfoResponse = contractService.contractInfo(contractInfoRequest);
        return Results.newSuccessResult(contractInfoResponse);
    }
    @PostMapping("/feign/contract/createContract")
    @ApiOperation("创建合同")
    public FeignResult<CreateContractResponse> createContract(@RequestBody CreateContractRequest createContractRequest) {
        CreateContractResponse createContractResponse = contractService.saveContract(createContractRequest);
        return Results.newSuccessResult(createContractResponse);
    }

    @PostMapping("/feign/contract/contractInfoBySignTaskId")
    @ApiOperation("根据合同任务id查询合同详情")
    public FeignResult<ContractInfoResponse> contractInfoBySignTaskId(@RequestBody ContractInfoRequest contractInfoRequest) {
        ContractInfoResponse contractInfoResponse = contractService.contractInfoBySignTaskId(contractInfoRequest);
        return Results.newSuccessResult(contractInfoResponse);
    }

    @PostMapping("/feign/contract/signFinished")
    @ApiOperation("签约完成事件")
    public FeignResult<ContractInfoResponse> signFinished(@RequestBody ContractSignFinishedRequest contractSignFinishedRequest) {
        ContractInfoResponse contractInfoResponse = contractService.signFinished(contractSignFinishedRequest);
        return Results.newSuccessResult(contractInfoResponse);
    }

    /**
     * 条件查询合同列表
     *
     * @param contractInfoListRequest
     * @return
     */
    @PostMapping("/feign/contract/contractInfoList")
    @ApiOperation("条件查询合同列表")
    public FeignResult<ContractInfoListResponse> contractInfoList(@RequestBody ContractInfoListRequest contractInfoListRequest) {
        ContractInfoListResponse contractInfoListResponse = contractFeignService.contractInfoList(contractInfoListRequest);
        return Results.newSuccessResult(contractInfoListResponse);
    }

    /**
     * 撤销合同签署任务
     *
     * @param request
     * @return
     */
    @PostMapping("/feign/contract/cancelContract")
    @ApiOperation("撤销合同签署任务")
    public FeignResult<ContractSignTaskCancelResponse> cancelContract(@RequestBody ContractSignTaskCancelRequest request) {
        ContractSignTaskCancelResponse response = contractFeignService.cancelContractSignTask(request);
        return Results.newSuccessResult(response);
    }


}
